package com.mall.search.controller;

import com.mall.search.model.SkuEs;
import com.mall.search.service.SkuSearchService;
import com.mall.util.RespResult;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Map;

/**
 * @author ljr
 * @version 1.0
 * @description: TODO
 * @date 2021/9/8 22:18
 */
@RestController
@RequestMapping(value = "/search")
public class SkuSearchController {

    @Resource
    private SkuSearchService skuSearchService;

    /***
     * 商品搜索
     */
    @GetMapping
    public RespResult<Map<String,Object>> search(@RequestParam(required = false)Map<String,Object> searchMap){
        Map<String, Object> resultMap = skuSearchService.search(searchMap);
        return RespResult.ok(resultMap);
    }

    /*****
     * 增加索引
     */
    @PostMapping(value = "/add")
    public RespResult add(@RequestBody SkuEs skuEs){
        skuSearchService.add(skuEs);
        return RespResult.ok();
    }

    /***
     * 删除索引
     */
    @DeleteMapping(value = "/del/{id}")
    public RespResult del(@PathVariable(value = "id")String id){
        skuSearchService.delete(id);
        return RespResult.ok();
    }
}
